<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <script>

        // addEventListener('click' ,fn)
        // document.addEventListener('click', function () {
        //     console.log(666);
        // })

        // IE8及以下  事件监听的绑定方式  attachEvent('onclick' , fn)
        // document.attachEvent('onclick', function () {
        //     console.log(777);
        // })

        addEvent(document, 'click', function () {
            console.log(888);
        })


        // 绑定事件的兼容写法
        function addEvent(ele, type, cb) {
            if (window.addEventListener) {
                ele.addEventListener(type, cb)
            } else {
                ele.attachEvent('on' + type, cb)
            }
        }

    </script>

</body>

</html>